package Jihe;

import javax.swing.*;
import java.util.Comparator;
import java.util.Objects;

public class Cat implements Comparable<Cat> {
    private String name;
    private String sex;
    private int age ;
    private int hashcode;

    public Cat() {
    }
    public Cat(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        hashcode = hashCode();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Cat cat = (Cat) o;
        return age == cat.age && Objects.equals(name, cat.name) && Objects.equals(sex, cat.sex);
    }

    public int hashCode() {
        return Objects.hash(name, sex, age);
    }

    public int compareTo(Cat o) {
        return this.hashcode-o.hashcode;
    }
}
